浏览量 4467
2019/03/31 13:20
示例:点击 -> 性能监控
/proc/meminfo used=total-(buffers+cached+free)
[root@wangzi go]# cat /proc/meminfo
MemTotal: 1016212 kB
MemFree: 77724 kB
MemAvailable: 51692 kB
Buffers: 8468 kB
Cached: 59584 kB
python监控代码:
#!/usr/bin/env python
# coding=utf-8
# author: brownwang
# mail: 277215243@qq.com
# datetime:2019/3/31 1:03 PM
# web: https://www.bthlt.com
def mem_use():
free=0
used=0
total=0
buffers=0
cached=0
with open('/proc/meminfo','r') as file:
for line in file.readlines():
if line.startswith('MemTotal:'):
total=line.split()[1]
if line.startswith('MemFree:'):
free=line.split()[1]
if line.startswith('Cached:'):
cached=line.split()[1]
if line.startswith('Buffers:'):
buffers=line.split()[1]
used=int(total)-int(free)-int(cached)-int(buffers)
insert_sql="""insert into `monitor_mem_use` (`used`,`free`,`cached`,`buffers`,`flow_time`) values ({0},{1},{2},{3},'{4}')""".format(used,free,cached,buffers,now_zero)
cursorUpdate(insert_sql,[])
上一篇 搜索 下一篇